package com.lzrj.server;

import java.util.LinkedList;
import java.util.List;

public class Webapp {

    private String context;
    private String path;

    public String getContext() {
        return context;
    }

    public void setContext(String context) {
        this.context = context;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public static List<Webapp> parse(List<String> webapp,List<String> context){
        LinkedList<Webapp> webapps = new LinkedList<>();
        for (int i = 0; i < webapp.size(); i++) {
            String appStr = webapp.get(i);
            Webapp app = new Webapp();
            if (appStr.contains(":")){
                String[] contextAndApp = appStr.split(":");
                app.setContext(contextAndApp[0]);
                app.setPath(contextAndApp[1]);
            }else {
                if (context != null && i < context.size()){
                    app.setContext(context.get(i));
                }
                app.setPath(appStr);
            }
            webapps.add(app);
        }

        return webapps;
    }

}
